#ifndef _THREAD_WORKER_H_
#define _THREAD_WORKER_H_

#include <map>
#include <string>

#ifdef _WIN32
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
#endif

class Worker
{
protected:
	typedef DWORD TaskFunc(LPVOID *);

	typedef std::map<int, void *> ArgumentList;
	typedef std::pair<int, void *> ArgumentItem;
	typedef std::map<int, void *>::iterator ArgumentIter;

public:
	Worker();
	Worker(TaskFunc function);

	void addArgument(int ArgumentID, void *);
	template<class T> T *getArgument(int ArgumentID);
	void delArgument(int ArgumentID);

	void setProcess(TaskFunc function);
	void setFlags(int flags);

	bool start();
	bool terminate();
	bool terminate(bool wait);

protected:
	DWORD _threadId;
	HANDLE _thread;
	TaskFunc *_function;

	int _flags;
	ArgumentList _arguments;
};

#endif